#业务类：登录业务
import time

import allure

#导入和该业务有关的N个页面类
from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

class ServiceLogin(object):
    def __init__(self,driver,base_url):
        #初始化和该业务有关的N个页面类对象
        self.pageIndex=PageIndex(driver,base_url)
        self.pageLogin=PageLogin(driver,base_url)
        self.pageUser=PageUser(driver,base_url)

    def service_login_01(self,d):
            #首页页面的实现
            allure.attach("","打开首页")
            self.pageIndex.openUrl()
            allure.attach("", "点击首页上的登录按钮")
            self.pageIndex.click_loginButton()

            #登录页面的实现
            allure.attach("", f"输入账号:{d['zanhao']}")
            self.pageLogin.input_zanhao(d["zanhao"])
            self.pageLogin.input_pwd(d["pwd"])
            self.pageLogin.click_login()
            time.sleep(2)


            #个人中心页面的实现
            imgName=self.pageUser.savePng3("登录",d['key']) #"登录_K01_20250803113801"
            allure.attach(open(f'./screen/{imgName}.png', 'rb').read(), "点击登录按钮后的web截图",allure.attachment_type.PNG)
            siji=self.pageUser.getNichenH2Text() #"nswe，欢迎光临"
            yuqi=d["yuqi"]
            return siji==yuqi


    def service_login_02(self,d):
            #首页页面的实现
            self.pageIndex.openUrl()
            self.pageIndex.click_loginButton()

            #登录页面的实现
            self.pageLogin.input_zanhao(d["zanhao"])
            self.pageLogin.input_pwd(d["pwd"])
            self.pageLogin.click_login()

            # return self.pageLogin.isExistsErrorTipDiv()

            siji=self.pageLogin.getErrorTipDivText()
            yuqi=d["yuqi"]
            return yuqi in siji

    def service_login_03(self,d):
            #首页页面的实现
            self.pageIndex.openUrl()
            self.pageIndex.click_loginButton()

            #登录页面的实现
            self.pageLogin.input_zanhao(d["zanhao"])
            self.pageLogin.input_pwd(d["pwd"])
            self.pageLogin.click_login()

            siji=self.pageLogin.getPwdAttrClass() #"input_text    invalid-text"
            return "invalid-text" in siji

    def service_login_04(self,d):
            #首页页面的实现
            self.pageIndex.openUrl()
            self.pageIndex.click_loginButton()

            #登录页面的实现
            self.pageLogin.input_zanhao(d["zanhao"])
            self.pageLogin.input_pwd(d["pwd"])
            self.pageLogin.click_login()

            siji=self.pageLogin.getZanhaoAttrClass()
            return "invalid-text" in siji


